package com.cvmars.jianyou.module.activity

import android.os.Bundle
import android.view.View
import android.widget.Button

import com.cvmars.jianyou.R
import com.cvmars.jianyou.api.api.Api
import com.cvmars.jianyou.api.api.HttpUtils
import com.cvmars.jianyou.api.api.SimpleSubscriber
import com.cvmars.jianyou.api.model.HttpResult
import com.cvmars.jianyou.config.MyConfig
import com.cvmars.jianyou.model.ImageModel
import com.cvmars.jianyou.module.base.BaseActivity
import com.cvmars.jianyou.module.base.BaseImagePagerActivity
import com.cvmars.jianyou.module.base.BaseWebViewActivity
import com.cvmars.jianyou.module.model.TokenListModel
import com.cvmars.jianyou.utils.ToastUtils

import java.io.Serializable
import java.util.ArrayList

import butterknife.BindView
import butterknife.ButterKnife
import butterknife.OnClick

class MainActivity : BaseActivity() {


    @BindView(R.id.btn_imgs)
    internal var btnImgs: Button? = null
    @BindView(R.id.btn_webview)
    internal var btnWebview: Button? = null

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        ButterKnife.bind(this)

        val str = "hello"
    }


    /**
     * 测试请求
     */
    private fun testRequest() {

        //        HttpUtils.getInstance().toSubscribe(Api.getInstance().getHomeInfo(),
        //                new SimpleSubscriber<HttpResult<TokenListModel>>() {
        //                    @Override
        //                    protected void _onNext(HttpResult<TokenListModel> o) {
        //
        //                        if (o.isSucc()) {
        //
        //                            TokenListModel data = o.getData();
        //
        //                            ToastUtils.show(data.toString());
        //                        }
        //                    }
        //
        //                    @Override
        //                    protected void _onError(String message) {
        //
        //                    }
        //                });

    }


    @OnClick(R.id.btn_imgs, R.id.btn_webview)
    fun onViewClicked(view: View) {
        val bundle = Bundle()
        when (view.id) {
            R.id.btn_imgs -> {

                val listImgs = ArrayList<ImageModel>()

                val model = ImageModel()
                model.imgPath = "http://img3.imgtn.bdimg.com/it/u=411694744,3255505115&fm=200&gp=0.jpg"
                val model1 = ImageModel()
                model1.imgPath = "http://img5.imgtn.bdimg.com/it/u=3198611610,3108821463&fm=27&gp=0.jpg"
                listImgs.add(model)
                listImgs.add(model1)
                bundle.putSerializable(MyConfig.INTENT_DATA_URL, listImgs as Serializable)
                goActivity(bundle, BaseImagePagerActivity::class.java)
            }
            R.id.btn_webview -> {
                val urlStr = "https://www.jianshu.com/p/2f0fb7162a56"
                bundle.putSerializable(MyConfig.INTENT_DATA_URL, urlStr)
                goActivity(bundle, BaseWebViewActivity::class.java)
            }
        }
    }
}
